package com.blt.govdata.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.blt.govdata.controller.base.BaseController;
import com.blt.govdata.service.ITProjectPlanService;
import com.blt.govdata.service.ITProjectYearService;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 * @author AustinGJ123
 * @since 2018-03-26
 */
@RestController
@RequestMapping("/tProjectYear")
//todo 将所有的XXX修改为真实值
public class TProjectYearController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ITProjectYearService service;

    @Autowired
    private ITProjectPlanService planService;

    /**
     * 分页查询项目年度计划
     * 关键字查询：keyword
     */

    @RequestMapping(value = "/selectProjectProgressPage")
    public Map<String, Object> selectProjectProgressVoPage(@RequestParam Map<String, Object> params, Page page) {
        if (null == params.get("year")) params.put("year", Calendar.getInstance().get(Calendar.YEAR));
        params.put("userId",this.userid);
        if(StringUtils.containsAny(this.username,"admin","super")) params.remove("userId");
        Page<Map<String, Object>> result = service.selectProjectYearByPage(page, params);
//        List<Map<String,Object>> projects = result.getRecords();
//        Iterator it = projects.iterator();
//        while (it.hasNext()){
//            Map<String,Object> project  = (Map<String,Object>)it.next();
//            if(null != project){
//                List<TProjectPlan> list = this.planService.selectList(new EntityWrapper<TProjectPlan>().where("p_id = {0}",project.get("id")).and("year = {0}", Calendar.getInstance().get(Calendar.YEAR)));
//                project.put("plan",list);
//            }
//        }
        logger.info("分页项目年度计划");
        return ImmutableMap.of("status", "true", "data", result);
    }


}
